# Use an official Python runtime as a parent image
FROM python:3.10-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Create working directory
WORKDIR /app

ARG NEED_MIRROR=1

# 根据 NEED_MIRROR 参数决定是否更换 pip 源
RUN if [ "$NEED_MIRROR" = "1" ]; then \
        pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple pip --upgrade && \
        pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple; \
    else \
        echo "Using default PyPI source"; \
    fi

# Install pip dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY . .

# Expose the application port
EXPOSE 9383

# Command to run the application
CMD ["uvicorn", "mail_mcp_server:starlette_app", "--host", "0.0.0.0", "--port", "9383"]